<template>
    <view class="columnbox content">


        <view class="top-box def-bgcol columnbox">
            <view class="rowbox store-info">
                <view class="columnbox als store-detail">
                    <view class="" v-if="userinfo.shanghuid==0||storeinfo.status==1">
                        未开通门店
                    </view>
                    <view class="" v-else>
                        <view class="info-title">营业中></view>
                        <view>身份：{{userinfo.state==1?'老板':'店员'}}</view>
                        <view>名称：{{storeinfo.name||'-'}}</view>
                    </view>
                </view>
                <view class="columnbox show-btn" @click="handleViewStore"
                    v-if="userinfo.shanghuid!==0&&storeinfo.status==2">
                    <image src="../../static/img/shop.png" mode="widthFix"></image>
                    <view style="font-size: 24rpx;">查看小程序店铺</view>
                </view>
            </view>
        </view>
        <view class="columnbox modular-box count-box">
            <view class=" wdh-100  warpcont">
                <view class="titcont">
                    <view class="left">
                        今日收款总额
                    </view>
                    <view class="right" @click="handleGoskrecord">
                        明细
                    </view>
                </view>

                <view class="columnbox cloum-item cloum-item2">
                    <view class="order-count2">¥{{tongjiInfo.priceday||0}}</view>
                </view>
                <view class="fukuan">
                    <view class="item">
                        <view class="label">
                            余额付款
                        </view>
                        <view class="val">
                            ￥{{tongjiInfo.priceyue||0}}
                        </view>
                    </view>
                    <view class="item">
                        <view class="label">
                            微信付款
                        </view>
                        <view class="val">
                            ￥{{tongjiInfo.pricewx||0}}
                        </view>
                    </view>
                    <view class="item">
                        <view class="label">
                            支付宝付款
                        </view>
                        <view class="val">
                            ￥{{tongjiInfo.priceal||0}}
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <view class="columnbox modular-box count-box" style="margin-top: 20rpx;">
            <view class=" wdh-100 warpcont">
                <view class="titcont">
                    <view class="left">
                        充值
                    </view>
                    <view class="right" @click="handleGoczrecord">
                        明细
                    </view>
                </view>
                <view class="columnbox cloum-item">
                    <view class="order-title">今日新增充值</view>
                    <view class="order-count">￥{{tongjiInfo.yueday||0}}</view>
                </view>
                <view class="columnbox cloum-item">
                    <view class="order-title">总充值</view>
                    <view class="order-count">￥{{tongjiInfo.yue||0}}</view>
                </view>

            </view>

        </view>
        <view class="columnbox modular-box count-box" style="margin-top: 20rpx;">
            <view class=" wdh-100 warpcont">
                <view class="titcont">
                    <view class="left">
                        用户
                    </view>

                </view>
                <view class="columnbox cloum-item">
                    <view class="order-title">总注册用户</view>
                    <view class="order-count">{{tongjiInfo.usernumday||0}}</view>
                </view>
                <view class="columnbox cloum-item">
                    <view class="order-title">今日新增注册用户</view>
                    <view class="order-count">{{tongjiInfo.usernum||0}}</view>
                </view>
                <view class="columnbox cloum-item">
                    <view class="order-title">总充值用户数</view>
                    <view class="order-count">{{tongjiInfo.czusernum||0}}</view>
                </view>
                <view class="columnbox cloum-item">
                    <view class="order-title">今日新增充值用户</view>
                    <view class="order-count">{{tongjiInfo.czusernumday||0}}</view>
                </view>
            </view>

        </view>
       <!-- <view class="rowbox one-modular spb" @click="goodsManage">
            <view>线上商城</view>
            <u-icon name="arrow-right" size="28rpx"></u-icon>
        </view>
        <view class="rowbox one-modular spb" @click="showOrder">
            <view>商品订单管理</view>
            <u-icon name="arrow-right" size="28rpx"></u-icon>
        </view>
        <view class="rowbox one-modular spb" @click="showRechargeGo">
            <view>充值购订单</view>
            <u-icon name="arrow-right" size="28rpx"></u-icon>
        </view>

        <view class="rowbox one-modular spb" @click="showMember" v-if="userinfo.state==1">
            <view>店员管理</view>
            <u-icon name="arrow-right" size="28rpx"></u-icon>
        </view> -->
    </view>
</template>

<script>
    import auth from '@/utils/auth.js'
    import IosKefu from '@/components/ioskefu.vue'
    export default {
        components: {
            IosKefu
        },
        data() {
            return {
                matype: '',
                showIosKefu: false,
                tongjiInfo: '',
                logflag: false,
                userinfo: null,
                storeinfo: null,
                showmapop: false,
                ma: '',
            }
        },
        onLoad() {},
        onShow() {
            if (uni.getStorageSync('uid')) {
                this.logflag = true
                this.userinfo = uni.getStorageSync('userInfo')
                if (this.userinfo.shanghuid == 0) {
                    this.getUserInfo()
                } else {
                    this.getStoreInfo()
                }
                this.getTongji()
            } else {
                this.storeinfo = ''
                this.logflag = false
            }
        },
        methods: {
            showStatistics() {
                if (uni.getStorageSync('userInfo').shanghuid == 0) {
                    uni.navigateTo({
                        url: '/pages/index/statistics'
                    })
                    return
                } else {
                    uni.navigateTo({
                        url: '/pages/iden/edit'
                    })
                }
            },
            editStore() {
                if (uni.getStorageSync('userInfo').shanghuid == 0) {
                    uni.navigateTo({
                        url: '/pages/iden/iden'
                    })
                    return
                } else {
                    uni.navigateTo({
                        url: '/pages/iden/edit'
                    })
                }
            },
            async showDuibiPay() {
                let data = await auth.getAuth('hy', 'hyinttime', '/pages/duibiPay/duibiPay')
                if (!data) {
                    this.showIosKefu = true
                    this.matype = 'hyimg'
                }
            },
            showMyStore() {
                uni.navigateToMiniProgram({
                    appId: 'wx42f52aeb0203685a'
                })
            },
            handleShowMa() {
                if (uni.getStorageSync('userInfo').shanghuid == 0) {
                    uni.navigateTo({
                        url: '/pages/iden/iden'
                    })
                    return
                }
                this.$req.post('/shanghu/shanghuInfo', {
                    shanghuid: uni.getStorageSync('userInfo').shanghuid
                }).then(res => {
                    this.ma = res.data.data.erweima
                    this.showmapop = true
                })
            },
            handleDownMa() {
                this.downSaveImage(this.ma)
            },
            downSaveImage(imgurl) {
                uni.getSetting({
                    success(res) {
                        if (res.authSetting['scope.writePhotosAlbum']) {
                            // 已授权，直接保存图片
                            uni.downloadFile({
                                url: imgurl,
                                success: (res) => {
                                    if (res.statusCode === 200) {
                                        uni.saveImageToPhotosAlbum({
                                            filePath: res.tempFilePath,
                                            success: function() {
                                                uni.showToast({
                                                    title: '已保存到相册',
                                                    duration: 2000,
                                                })
                                            },
                                            fail: function() {
                                                uni.showToast({
                                                    title: '保存失败，请稍后重试',
                                                    icon: 'none',
                                                })
                                            },
                                        })
                                    }
                                },
                            })
                        } else if (res.authSetting['scope.writePhotosAlbum'] === false) {
                            // 用户已拒绝授权，提示用户授权
                            uni.showModal({
                                title: '提示',
                                content: '您未授权保存图片到相册，是否前往设置页面进行授权？',
                                success: function(res) {
                                    if (res.confirm) {
                                        uni.openSetting({
                                            success: function(res) {
                                                if (res.authSetting[
                                                        'scope.writePhotosAlbum']) {
                                                    uni.downloadFile({
                                                        url: imgurl,
                                                        success: (res) => {
                                                            if (res
                                                                .statusCode ===
                                                                200) {
                                                                uni.saveImageToPhotosAlbum({
                                                                    filePath: res
                                                                        .tempFilePath,
                                                                    success: function() {
                                                                        uni.showToast({
                                                                            title: '已保存到相册',
                                                                            duration: 2000,
                                                                        })
                                                                    },
                                                                    fail: function() {
                                                                        uni.showToast({
                                                                            title: '保存失败，请稍后重试',
                                                                            icon: 'none',
                                                                        })
                                                                    },
                                                                })
                                                            }
                                                        },
                                                    })
                                                }
                                            },
                                        })
                                    } else if (res.cancel) {
                                        uni.showToast({
                                            title: '您取消了授权',
                                            icon: 'none',
                                            duration: 2000,
                                        })
                                    }
                                },
                            })
                        } else {
                            // 用户第一次调用，调用授权接口
                            uni.authorize({
                                scope: 'scope.writePhotosAlbum',
                                success() {
                                    uni.downloadFile({
                                        url: imgurl,
                                        success: (res) => {
                                            if (res.statusCode === 200) {
                                                uni.saveImageToPhotosAlbum({
                                                    filePath: res.tempFilePath,
                                                    success: function() {
                                                        uni.showToast({
                                                            title: '保存成功',
                                                            duration: 2000,
                                                        })
                                                    },
                                                    fail: function() {
                                                        uni.showToast({
                                                            title: '保存失败，请稍后重试',
                                                            icon: 'none',
                                                        })
                                                    },
                                                })
                                            }
                                        },
                                    })
                                },
                                fail() {
                                    uni.showToast({
                                        title: '授权失败，请稍后重试',
                                        icon: 'none',
                                        duration: 2000,
                                    })
                                },
                            })
                        }
                    },
                })
            },
            async showCoupon() {
                let data = await auth.getAuth('yhj', 'yhjinttime', '/pages/coupon/coupon')
                if (!data) {
                    this.showIosKefu = true
                    this.matype = 'yhjimg'
                }
            },
            showWenAn() {
                uni.switchTab({
                    url: '/pages/document/document'
                })
            },
            async showQuickSale() {
                // let data = await auth.getAuth('dpkm', 'dpkminttime', '/pages/quicksale/quicksale')
                // if (!data) {
                // 	this.showIosKefu = true
                // 	this.matype = 'dpkmimg'
                // }
                uni.navigateTo({
                    url: '/pages/quicksale/quicksale'
                })
            },
            async showRecharge() {
                let data = await auth.getAuth('hy', 'hyinttime', '/pages/recharge/recharge')
                if (!data) {
                    this.showIosKefu = true
                    this.matype = 'hyimg'
                }
            },
            closeIosKefu() {
                this.showIosKefu = false
            },
            handleGoczrecord() {
                if (uni.getStorageSync('uid')) {
                    if (this.userinfo.shanghuid == 0) {
                        uni.navigateTo({
                            url: '/pages/iden/iden'
                        })
                    } else {
                        uni.navigateTo({
                            url: '/pages/rechargerecord/rechargerecord'
                        })
                    }

                } else {
                    uni.navigateTo({
                        url: '/pages/log/log'
                    })
                }
            },
            handleGoskrecord() {
                if (uni.getStorageSync('uid')) {
                    if (this.userinfo.shanghuid == 0) {
                        uni.navigateTo({
                            url: '/pages/iden/iden'
                        })
                    } else {
                        uni.navigateTo({
                            url: '/pages/collectionrecord/collectionrecord'
                        })
                    }

                } else {
                    uni.navigateTo({
                        url: '/pages/log/log'
                    })
                }
            },

            handleViewStore() {
                uni.navigateToMiniProgram({
                    appId: 'wx42f52aeb0203685a',
                    path: `/pages/index/index?shanghuid=${this.userinfo.shanghuid}`
                })
            },
            getTongji() {
                this.$req.post('/shanghu/baobiao', {
                    shanghuid: this.userinfo.shanghuid
                }).then((res) => {
                    this.tongjiInfo = res.data.data
                })
            },
            async showRechargeGo() {
                let data = await auth.getAuth('czg', 'czginttime', '/pages/goorder/goorder')

                if (!data) {
                    this.showIosKefu = true
                    this.matype = 'czgimg'
                }
            },
            async showVip() {

                let data = await auth.getAuth('hy', 'hyinttime', '/pages/vip/vip')
                if (!data) {
                    this.showIosKefu = true
                    this.matype = 'hyimg'
                }
            },
            goWxDiscount() {
                if (uni.getStorageSync('uid')) {
                    if (this.userinfo.shanghuid == 0) {
                        uni.navigateTo({
                            url: '/pages/iden/iden'
                        })
                    } else {
                        uni.navigateTo({
                            url: '/pages/wxdiscount/wxdiscount'
                        })
                    }

                } else {
                    uni.navigateTo({
                        url: '/pages/log/log'
                    })
                }
            },

            async showRechargeBuy() {
                uni.navigateTo({
                    url: '/pages/rechargebuylist/rechargebuylist'
                })
                // let data = await auth.getAuth('czg', 'czginttime', '/pages/rechargebuylist/rechargebuylist')
                // if (!data) {
                // 	this.showIosKefu = true
                // 	this.matype = 'czgimg'
                // }
            },


            async goodsManage() {
                let data = await auth.getAuth('sc', 'scinttime', '/pages/goods/goods')
                if (!data) {
                    this.showIosKefu = true
                    this.matype = 'scimg'
                }
            },

            getUserInfo() {
                this.$req.post('/shanghu/userInfo', {
                    uid: uni.getStorageSync('uid')
                }).then(res => {

                    this.userinfo = res.data.data
                    this.getStoreInfo()
                })
            },
            getStoreInfo() {

                this.$req.post('/shanghu/shanghuInfo', {
                    shanghuid: this.userinfo.shanghuid
                }).then(res => {
                    this.storeinfo = res.data.data
                })
            },
            toIden() {
                if (uni.getStorageSync('uid')) {
                    uni.navigateTo({
                        url: '/pages/iden/iden'
                    })
                } else {
                    uni.navigateTo({
                        url: '/pages/log/log'
                    })
                }
            },

            async showMember() {
                if (uni.getStorageSync('uid')) {
                    if (this.userinfo.shanghuid == 0) {
                        uni.navigateTo({
                            url: '/pages/iden/iden'
                        })
                    } else {
                        uni.navigateTo({
                            url: '/pages/member/member'
                        })
                    }
                } else {
                    uni.navigateTo({
                        url: '/pages/log/log'
                    })
                }

            },
            async showOrder() {
                // let data = await auth.getAuth('sc', 'scinttime', '/pages/order/order')
                // if (!data) {
                // 	this.showIosKefu = true
                // 	this.matype = 'scimg'
                // }
                uni.reLaunch({
                    url: '/pages/order/order'
                })

            }
        }
    }
</script>

<style lang="scss" scoped>
    .warpcont {
        flex-wrap: wrap;
        display: flex;

        .titcont {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 28rpx;
            width: 100%;
            padding-bottom: 20rpx;

            .left {

                font-weight: 500;
            }

            .right {
                color: #09f;
            }
        }

        .shu {
            margin-bottom: 20rpx;
            width: 100%;
            height: 1px;

            background-color: #edf0f2;
        }

        .cloum-item {
            width: 50%;
            padding-bottom: 20rpx;
        }

        .cloum-item2 {
            width: 33.33%;
        }

        .fukuan {
            width: 100%;
            display: flex;

            .item {
                padding-top: 5rpx;
                display: flex;
                align-items: center;
                flex-direction: column;
                justify-content: center;
                width: 33.33%;
                padding-bottom: 20rpx;

                .label {
                    font-size: 24rpx;
                    color: #a7a7a7;
                }

                .val {
                    padding-top: 20rpx;
                    font-size: 32rpx;
                    font-weight: 500;
                }
            }
        }
    }

    .content {
        width: 100%;
        padding-bottom: 20rpx;
        min-height: 100vh;
        justify-content: flex-start;
    }

    .top-box {
        width: 100%;
        color: #fff;
        padding: 20rpx 20rpx;
        padding-bottom: 100rpx;
    }

    .iden-box {
        background: linear-gradient(to right, #f5d1b3, #f4d9c6);
        width: 100%;
        justify-content: space-between;
        padding: 20rpx 20rpx;
        border-radius: 10rpx;
        color: #965630;
        font-size: 32rpx;
    }

    .iden-btn {
        background: #4d2d1b;
        color: #fff;
        padding: 10rpx 20rpx;
        border-radius: 10rpx;
        font-size: 24rpx;
        line-height: 40rpx;
    }

    .store-info {
        width: 100%;
        justify-content: space-between;
        align-items: flex-end;
    }

    .store-detail {
        margin-top: 20rpx;
        color: #fff;
        line-height: 50rpx;
        font-size: 26rpx;

        .info-title {
            font-size: 32rpx;
            line-height: 60rpx;
        }
    }

    .show-btn {
        width: 200rpx;
        font-size: 28rpx;
        color: #fff;


        image {
            margin-bottom: 10rpx;
            width: 50rpx;
            height: 50rpx;
        }
    }

    .modular-box {
        width: 710rpx;
        background: #fff;
        padding: 32rpx 32rpx;
        border-radius: 20rpx;
    }

    .count-box {
        margin-top: -70rpx;
    }

    .order-title {
        font-size: 24rpx;
        color: #a7a7a7;
    }

    .order-count {
        width: 100%;
        // font-size: 40rpx;
        padding-top: 20rpx;
        color: #000;
        font-size: 32rpx;
        font-weight: 500;
        // margin-top: 20rpx;


        text-align: center;
    }

    .order-count2 {
        width: 100%;
        // font-size: 40rpx;

        color: #000;
        font-size: 32rpx;
        font-weight: 500;
        // margin-top: 20rpx;


        text-align: center;
    }

    .order-num {
        border-bottom: #ebebeb solid 1px;
    }

    .order-modular {
        font-size: 28rpx;
        justify-content: space-between;
        margin-top: 32rpx;
        width: 100%;
    }

    .one-modular {
        background: #fff;
        border-radius: 20rpx;
        font-size: 28rpx;
        margin-top: 20rpx;
        padding: 32rpx 32rpx;
        width: 710rpx;
    }

    .modular-info {
        padding: 32rpx 32rpx;
        border-bottom: #f7f5f9 solid 1px;
    }

    .m-box {
        background: #F5F5F5;
        border-radius: 20rpx;
        margin: 20rpx 0;
        padding: 32rpx 26rpx;

        image {
            height: 40rpx;
        }

        .btn-one {
            position: relative;
            background: #fff;
            height: 100rpx;
            width: 100%;
            border-radius: 20rpx;
            box-shadow: 0 1px 4px 2px #e7eaea;
            line-height: 32rpx;
        }
    }

    .czg {
        width: 40rpx;
        height: 40rpx;
        margin-right: 14rpx;
    }

    .btn-title {
        font-weight: bold;
        font-size: 26rpx;
        color: #000000;
    }

    .btn-desc {
        font-size: 20rpx;
        color: #ff8429;
    }

    .btn-arrow {
        width: 40rpx;
        height: 40rpx;
        position: absolute;
        right: 20rpx;
    }

    .m-box-two {
        border-radius: 20rpx;
        padding: 0 26rpx;

        .more-title {
            font-size: 26rpx;
        }
    }

    .module-list {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;

        .one-box {
            width: 107rpx;
            height: 107rpx;
            margin-top: 32rpx;
            margin-right: 40rpx;
            box-shadow: 0 2px 4px 2px #e7ebee;
            border-radius: 20rpx;
            font-size: 20rpx;
            color: #222222;
        }

        image {
            width: 40rpx;
            height: 40rpx;
            margin-bottom: 10rpx;
        }
    }

    .module-list view:nth-child(5n) {
        margin-right: 0;
    }

    .phonePop {
        width: 90vw;
        display: flex;
        flex-direction: column;
        // align-items: center;
        padding: 30rpx 24rpx 30rpx 24rpx;
        min-height: 500rpx;

        .imgcont {
            padding-top: 30rpx;
            width: 400rpx;
            margin: 0 auto;

            .img {
                display: block;
                width: 100%;
                height: 100%;
            }
        }

        .tit {
            font-size: 30rpx;
            font-weight: 500;
            flex-shrink: 0;
            text-align: center;
        }

        .name {
            font-size: 28rpx;
            margin-top: 30rpx;
            flex: 1;
            padding: 0 20rpx;
        }

        .namecenter {
            text-align: center;
        }



        .footer-btn {
            flex-shrink: 0;
            padding-top: 30rpx;
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;

            .btn {
                line-height: 35rpx;
                width: calc(50% - 15rpx);
                padding: 20rpx;
                border-radius: 8rpx;
                font-size: 30rpx;
                font-weight: 500;
                text-align: center;
                background-color: #f5f5f5;
            }

            .confirmbtn {
                background-color: #57bd6a;
                color: #fff;
            }
        }

        .btncenter {
            justify-content: center;
        }
    }
</style>